package main

import "fmt"

/*
map的使用方式
(1)方式1
var a map[string]string
a=make(map[string]string,10)
(2)方式2
var a = make(map[string]string)
(3)方式3
var a map[string]string = map[string]string{
	"no4":"武汉",
}
a["no1"]="湖北"
*/
func main() {
	//方式1
	var a map[string]string
	a = make(map[string]string, 10)
	a["no1"] = "猪猪"
	fmt.Println(a)

	//方式2
	b := make(map[string]string)
	b["no1"] = "武汉"
	fmt.Println(b)

	//方式3
	var heroes map[string]string = map[string]string{
		"hero1": "猪猪",
	}
	heroes["hero2"] = "港港"
	fmt.Println("heroes=", heroes)

	//案例
	/*
		演示一个key-value的value是map的案例
		比如：要存放3个学生信息，每个学生有name和sex信息
		思路：map[string]map[string]string
	*/
	studentMap := make(map[string]map[string]string)
	studentMap["stu01"] = make(map[string]string, 3) //这句话不能少
	studentMap["stu01"]["name"] = "港港"
	studentMap["stu01"]["sex"] = "男"
	studentMap["stu01"]["address"] = "武汉"

	studentMap["stu02"] = make(map[string]string, 3) //这句话不能少
	studentMap["stu02"]["name"] = "猪猪"
	studentMap["stu02"]["sex"] = "女"
	studentMap["stu02"]["address"] = "武汉"
	fmt.Println(studentMap)
	fmt.Println(studentMap["stu02"])
	fmt.Println(studentMap["stu02"]["address"])
}
